<template>
  <div class="roleCls">
    <el-card>
      <div class="roleLine">
        <h3>筛选搜索</h3>
        <div>
          <el-button>重置</el-button>
          <el-button type="primary">查询搜索</el-button>
        </div>
      </div>
      <div style="margin-left:30px;">
        输入搜索：
        <el-input class="searchInput" placeholder="角色名称"></el-input>
      </div>
    </el-card>
    <el-card>
      <el-button>添加角色</el-button>
    </el-card>
    <el-card>
      <table-base :tableData="tableData">
        <template>
        <el-table-column
          prop="id"
          label="编号"
          width="80">
        </el-table-column>
        <el-table-column
          prop="name"
          label="角色名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="description"
          label="描述">
        </el-table-column>
        <el-table-column
          prop="createdTime"
          label="添加时间">
        </el-table-column>
        <el-table-column
          label="操作"
          width="150"
          align="center">
          <template v-slot="{row}">
            <el-button
              type="text"
              size="small"
              @click="distributeMenu(row)">
              分配菜单</el-button>
            <el-button
              type="text"
              size="small"
              @click="distributeSource(row)">
              分配资源</el-button>
            <el-button
              type="text"
              size="small"
              @click="editFnc(row)">
              编辑</el-button>
            <el-button
              type="text"
              size="small"
              @click="deleteFnc(row)">
              删除</el-button>
          </template>
        </el-table-column>
        </template>
      </table-base>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="serverData.current"
        :page-sizes="[1, 3, 5, 7, 9]"
        :page-size="serverData.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="serverData.total"
        :disabled="$store.state.isShowLoading">
      </el-pagination>
    </el-card>
  </div>
</template>

<script lang="ts">
import { getRolePages } from '@/api/role'
import Vue from 'vue'
import type { IRoleRecords, IRolePagesInfo } from '@/api/types/index'
export default Vue.extend({
  name: 'rolePage',
  data () {
    return {
      tableData: [] as IRoleRecords[],
      serverData: {
        size: 3,
        current: 1
      } as IRolePagesInfo
    }
  },
  created () {
    this.getRolePagesInfo()
  },
  methods: {
    async getRolePagesInfo () {
      const data = await getRolePages(
        {
          current: this.serverData.current,
          size: this.serverData.size
        })
      console.log('数据', data)
      this.tableData = data.records
      this.serverData = data
    },
    distributeMenu (row:IRoleRecords) {
      console.log(row)
    },
    distributeSource (row:IRoleRecords) {
      console.log(row)
    },
    editFnc (row:IRoleRecords) {
      console.log(row)
    },
    deleteFnc (row:IRoleRecords) {
      console.log(row)
    },
    handleSizeChange (val:number) {
      this.serverData.size = val
      this.serverData.current = 1
      this.getRolePagesInfo()
    },
    handleCurrentChange (val:number) {
      this.serverData.current = val
      this.getRolePagesInfo()
    }

  }
})
</script>

<style lang="scss" scoped>
.roleLine{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchInput{
  display: inline-block;
  width: 200px;
}

// ::v-deep .el-table tbody tr:hover>td {
//   background-color: var(--tableColor) !important;
// }

// ::v-deep .el-table__header-wrapper table thead th{
//   background-color: var(--tableColor) !important;
// }
</style>
